From 484a33af8c0d6634cbe39fcd36362f50f95c01f3 Mon Sep 17 00:00:00 2001 From: Behnam Esfahbod Date: Mon, 7 Aug 2017 09:31:32 -0700 Subject: [PATCH] [cargo_new] Hint to use `cargo init` on existing dir The `new` command always expects a non-existing path. The `init` command always expects an existing path. Therefore, it makes sense to hint to use `init` if the pre-condition to `new` is not satisfied. Fixes --- src/cargo/ops/cargo_new.rs | 8 +++++--- tests/new.rs | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 6320498f6..eddcd433c 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -268,12 +268,14 @@ fn plan_new_source_file(bin: bool, project_name: String) -> SourceFileInformatio pub fn new(opts: NewOptions, config: &Config) -> CargoResult<()> { let path = config.cwd().join(opts.path); if fs::metadata(&path).is_ok() { - bail!("destination `{}` already exists", - path.display()) + bail!("destination `{}` already exists\n\n\ + Use `cargo init` to initialize the directory\ + ", path.display() + ) } if opts.lib && opts.bin { - bail!("can't specify both lib and binary outputs"); + bail!("can't specify both lib and binary outputs") } let name = get_name(&path, &opts, config)?; diff --git a/tests/new.rs b/tests/new.rs index fa75d2da8..0e95caf02 100644 --- a/tests/new.rs +++ b/tests/new.rs @@ -111,7 +111,8 @@ fn existing() { fs::create_dir(&dst).unwrap(); assert_that(cargo_process("new").arg("foo"), execs().with_status(101) - .with_stderr(format!("[ERROR] destination `{}` already exists\n", + .with_stderr(format!("[ERROR] destination `{}` already exists\n\n\ + Use `cargo init` to initialize the directory", dst.display()))); } -- 2.30.2